/*
 * Copyright (C) 2010 Raimundo Mirisola (raimundo.mirisola@gmail.com)
 *
 * This program is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License as published by the Free Software
 * Foundation, either version 2 of the License, or (at your option) any later
 * version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
 * details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program. If not, see <http://www.gnu.org/licenses/>.
 */

package com.onerm.store;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

class OneRmDbOpenHelper extends SQLiteOpenHelper {

  public static final int DATABASE_VERSION = 1;
  public static final String DATABASE_NAME = "onermdb.db";

  public OneRmDbOpenHelper(Context context) {
    super(context, DATABASE_NAME, null, DATABASE_VERSION);
  }

  @Override
  public void onCreate(SQLiteDatabase db) {
    db.execSQL("CREATE TABLE bodypart ( muscle_id INTEGER PRIMARY KEY, bodypart_name VARCHAR(50) )");
    db.execSQL("CREATE TABLE exercise (  exercise_id INTEGER PRIMARY KEY,  exercise_name VARCHAR(200),  exercise_bodypart_id INTEGER,  FOREIGN KEY(exercise_bodypart_id) REFERENCES bodypart(bodypart_id));");
    db.execSQL("insert into exercise(exercise_name) values ('bench press')");
    db.execSQL("insert into exercise(exercise_name) values ('shoulder press')");
    db.execSQL("insert into exercise(exercise_name) values ('leg press')");
    db.execSQL("CREATE TABLE setlog (  setlogs_id INTEGER PRIMARY KEY,  setlog_num_reps INTEGER,  setlog_weight DOUBLE,  setlog_exercise_id INTEGER,  setlog_time DATE,  FOREIGN KEY(setlog_exercise_id) REFERENCES exercise(exercise_id));");
  }

  @Override
  public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
    // throw new IllegalStateException("Can't upgrade");
  }
}
